﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Com.ThrongIn.BLL;
using Com.ThrongIn.BE;

namespace ThrongIn
{
    /// <summary>
    /// Summary description for  Search Handler
    /// </summary> 
    public class SearchHandler : IHttpHandler, System.Web.SessionState.IRequiresSessionState
    {
        private class param
        {
            public string keywords = string.Empty;
        }

        public void ProcessRequest(HttpContext context)
        {
            string keywords = context.Request.Form[0];
            context.Response.ContentType = "text/json";
            var json = new System.Web.Script.Serialization.JavaScriptSerializer();
            param keys = json.Deserialize<param>(keywords);
            string jsonData = SearchProfileByKeywords(keys.keywords);
            context.Response.Write(jsonData);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        private string SearchProfileByKeywords(string keywords)
        {
            var json = new System.Web.Script.Serialization.JavaScriptSerializer();           
               
            List<Profile> profiles = new ProfileBLL().GetProfilesByKeywords(keywords);
            HttpContext.Current.Session["search"] = profiles;
            return json.Serialize(profiles);
        }

       
    }
}